﻿#include "ex02.h"


double fun02(double t)
{ 
	double ans;
	ans = pow(cos(t), 1.0 / 3);
	return ans; 
}

void ex02()
{
	double x = 0, eslong = 0.000001, x0;
	int N = 20, i;
	printf("\n近似初值 x0 = %lf\n", x);
	for (i = 0; i < N; i++) {
		x0 = x; 
		x = fun02(x);
		printf("第%d次迭代 x%d = %lf\n",i + 1, i + 1, x);
		if (fabs(x - x0) < eslong)
			break; 
	}
	if (fabs(x - x0) < eslong)
		printf("得到近似结果为 x ≈ %lf\n\n", x, i);
	else
		printf("迭代失败\n");
}